home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 34.zip
/
BS1 part 34
/
FredFish PD 314.adf
/
Zc
/
zcsrc.lzh
/
IOLib
/
stdio
/
fflush.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-18
|
1KB
|
60 lines
#include <stdio.h>
extern FILE _iob[];
int fflush(fp)
register FILE *fp;
/*
* implementation note: This function has the side effect of
* re-aligning the virtual file pointer (in the buffer) with
* the actual file pointer (in the file) and is therefore used
* in other functions to accomplish this re-sync operation.
*/
{
register int f, i;
if(fp)
return(_fflush(fp));
else
{
for(i=0; i<_NFILE; ++i)
{
f = _iob[i]._flag;
if(f & (_IOREAD | _IOWRT))
_fflush(&_iob[i]);
}
return(0);
}
}
static int _fflush(fp)
register FILE *fp;
{
register int f, rv = 0, c;
register long offset;
if(fp == NULL)
return(0);
f = fp->_flag;
if ((!(f & (_IOREAD | _IOWRT)))) /* file not open! */
return(0);
if(fp->_cnt){ /* data in the buffer */
if(f & _IORW) /* writing */
{
if(write(fp->_file, fp->_base, fp->_cnt) != fp->_cnt)
{
fp->_flag |= _IOERR;
rv = EOF;
}
}
else if ( !f & _IODEV ){ /* reading */
offset = -(fp->_cnt);
if (lseek(fp->_file, offset, 1) < 0)
rv = EOF;
}
}
fp->_ptr = fp->_base;
fp->_cnt = 0;
return(rv);
}